﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

using Leadtools;
using Leadtools.Codecs;
using Leadtools.WinForms;

using System.Runtime.InteropServices;
using System.Collections;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraGrid.Columns;
using Leadtools.ImageProcessing;
using MINERP.ComControls.Extension;

namespace MINERP.CustomerManage.DisposePhoto
{
    public partial class FrmDisposeMain : Form
    {
        //属性
        public int UserId { get; set; }
        private static FrmDisposeMain _instance;
        public static FrmDisposeMain GetInstance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new FrmDisposeMain();
                }
                return _instance;
            }
            set
            {
                _instance = value;
            }
        }

        //参数
        private BLL.CustomerManage.DisposePhotoBLL bll = new MINERP.BLL.CustomerManage.DisposePhotoBLL();

        public string StartOrderTotalPath;                  //等待开单总路径
        public string DisposeTotalPath;                     //员工理件的总路径
        private DataTable AllShop;
        private DataTable AllUser;                          //所有员工
        private TreeNode prePhotoNode;                      //点击节点，加载节点内照片时，判断当前节点是否与上一节点相等，相等就不用再加载
        public string SelectedShopName;                     //保存整理好的文件夹时，选中的商户名称
        public int SelectedShopId;                          //保存整理好的文件夹时，选中的商户Id
        public string SelectedUserName;                     //保存整理好的商户时，选中的开单员名称
        public int SelectedUserId;                          //保存整理好的商户时，选中的开单员Id

        public double NewHeight;                            //照片修改后的新高(修改高宽使用)
        public double NewWidth;                             //照片修改后的新宽(修改高宽使用)
        private bool ExAddPhoto = false;                    //强制加载文件夹内的照片(在修改了照片的高宽后)

        string StandardUnit = "";                           //修改照片尺寸的标准单位
        double StandardHeight = 0;                          //修改照片尺寸的标准高宽
        double StandardWidth = 0;

        private bool DisplayMode = false;                   //false照片列表 true缩略图     
        private RasterThumbnailBrowser browser = new RasterThumbnailBrowser();      //缩略图容器

        //API
        /// <summary>
        /// 移动文件，文件夹
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dst"></param>
        /// <param name="flag">1如果文件存在，则替换；2如移动到不同的卷，则复制文件并删除原来的文件；3移动操作在系统重启后才真正执行</param>
        /// <returns></returns>
        [DllImport("kernel32", EntryPoint = "MoveFileExW", CharSet = CharSet.Unicode)]
        public static extern bool MoveFile(string src, string dst, long flag);

        /// <summary>
        /// 创建文件夹
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        [DllImport("kernel32", EntryPoint = "CreateDirectory")]
        public static extern bool CreateDirectory(string path);

        /// <summary>
        /// 移除文件夹
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        [DllImport("kernel32", EntryPoint = "RemoveDirectory")]
        public static extern bool RemoveDirectory(string path);

        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        [DllImport("kernel32", EntryPoint = "DeleteFile")]
        public static extern bool DelFile(string path);

        /// <summary>
        /// 打开文件夹
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="lpszOp"></param>
        /// <param name="lpszFile"></param>
        /// <param name="lpszParams"></param>
        /// <param name="lpszDir"></param>
        /// <param name="FsShowCmd"></param>
        /// <returns></returns>
        [DllImport("shell32.dll", EntryPoint = "ShellExecute")]
        public static extern int OpenFolder(IntPtr hwnd, StringBuilder lpszOp, StringBuilder lpszFile, StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd);


        public FrmDisposeMain()
        {
            InitializeComponent();

            gvPhotoHW.ShowRowIndicator(50);
        }

        private void FrmDisposeMain_Load(object sender, EventArgs e)
        {
            //测试
            //UserId = 3;
            //StartOrderTotalPath = @"\\server1\Server上的文件备份\照片目录\等待开单";            //等待开单总路径
            //加载商户
            AllShop = bll.GetShops();               //所有有效的商户
            BindShop(AllShop);
            //加载员工
            BindUser();
            //加载理件树
            DisposeTotalPath = bll.GetUserDisposePhotoPath(UserId); //保存员工理件的总路径，在将理好件的文件夹转移到等待开单的时候使用                              
            AddTree();
            //设置缩略图的拖曳操作
            SetBrowserDrag();
        }

        //设置理件路径
        private void tsSetDisposePath_Click(object sender, EventArgs e)
        {
            try
            {
                if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                {
                    Cursor = Cursors.WaitCursor;
                    string path = folderBrowserDialog1.SelectedPath;
                    bll.UpdateUserDisposePath(UserId, path);
                    DisposeTotalPath = path;
                    //重新加载理件树
                    tvExplorer.Nodes.Clear();
                    lblTS.Visible = false;
                    AddTree();
                    Cursor = Cursors.Default;
                }
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                ShowMsg(ex.Message);
            }
        }

        //每次展开加载前两层
        private void tvExplorer_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;
                AddTwoLevel(e.Node);
                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                ShowMsg(ex.Message);
            }
        }
        //----------------方法---------------
        private void AddTree()
        {
            try
            {
                //判断员工是否有理件路径
                string path = DisposeTotalPath;
                if (path == "")
                {
                    lblTS.Text = "您的理件路径还未设置，请点击设置理件路径进行设置";
                    lblTS.Visible = true;
                    return;
                }
                //理件路径是否有效
                try
                {
                    if (Directory.Exists(path))
                    {
                        //加载理件树
                        AddRoot(path);
                    }
                    else
                    {
                        MessageBox.Show("理件路径无效，请重新设置！", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
                catch (Exception exx)
                {
                    if (exx is IOException)
                    {
                        MessageBox.Show("理件路径无效，请重新设置！", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 加载特殊的根目录，及下二层，因为默认根节点要展开，因此总共需加载3层
        /// </summary>
        /// <param name="path"></param>
        /// <param name="isRoot"></param>
        private void AddRoot(string path)
        {
            try
            {
                //根目录
                string nodeText = path.Substring(path.LastIndexOf("\\") + 1);
                FolderCL rootFolder = new FolderCL();
                rootFolder.FolderName = nodeText;
                rootFolder.IsRoot = true;
                rootFolder.Path = path;
                rootFolder.Level = 1;               //根节点从第一层开始
                TreeNode node = new TreeNode();
                node.Text = nodeText;
                node.Tag = rootFolder;
                tvExplorer.Nodes.Add(node);
                //第二层
                string[] directories = Directory.GetDirectories(path);
                foreach (string directory in directories)
                {
                    string subNodeText = directory.Substring(directory.LastIndexOf("\\") + 1);
                    if (!cbDisplayDisposed.Checked && subNodeText.Contains("OK"))                   //不显示已理件的文件夹
                        continue;
                    FolderCL subFolder = new FolderCL();
                    subFolder.FolderName = subNodeText;
                    subFolder.IsRoot = false;
                    subFolder.Path = subNodeText;
                    subFolder.Level = 2;
                    TreeNode subNode = new TreeNode();
                    subNode.Text = subNodeText;
                    subNode.Tag = subFolder;
                    if (subNodeText.Contains("OK"))
                        subNode.BackColor = Color.Pink;                 //已理好件的默认背景是PINK
                    node.Nodes.Add(subNode);
                    //第三层
                    string[] ssubDirectories = Directory.GetDirectories(directory);
                    foreach (string ssubDirectory in ssubDirectories)
                    {
                        string ssubNodeText = ssubDirectory.Substring(ssubDirectory.LastIndexOf("\\") + 1);
                        FolderCL ssubFolder = new FolderCL();
                        ssubFolder.FolderName = ssubNodeText;
                        ssubFolder.IsRoot = false;
                        ssubFolder.Path = ssubNodeText;
                        ssubFolder.Level = 3;
                        TreeNode ssubNode = new TreeNode();
                        ssubNode.Text = ssubNodeText;
                        ssubNode.Tag = ssubFolder;
                        subNode.Nodes.Add(ssubNode);
                    }
                }
                node.Expand();      //第一层默认展开
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void AddTwoLevel(TreeNode node)
        {
            try
            {
                //删除老节点
                node.Nodes.Clear();
                //得到当前节点的总路径
                string path = GetFullNodePath(node, "");
                FolderCL folder = (FolderCL)node.Tag;
                int level = folder.Level;
                //第一层
                string[] subDirectories = Directory.GetDirectories(path);
                foreach (string subDirectory in subDirectories)
                {
                    string subNodeText = subDirectory.Substring(subDirectory.LastIndexOf("\\") + 1);
                    if (!cbDisplayDisposed.Checked && subNodeText.Contains("OK"))                       //不显示已理件的文件夹
                        continue;
                    FolderCL subFolder = new FolderCL();
                    subFolder.FolderName = subNodeText;
                    subFolder.IsRoot = false;
                    subFolder.Path = subNodeText;
                    subFolder.Level = level + 1;
                    TreeNode subNode = new TreeNode();
                    subNode.Text = subNodeText;
                    subNode.Tag = subFolder;
                    if (subNodeText.Contains("OK"))
                    {
                        subNode.BackColor = Color.Pink;
                    }
                    node.Nodes.Add(subNode);
                    //第二层
                    string[] ssubDirectories = Directory.GetDirectories(subDirectory);
                    foreach (string ssubDirectory in ssubDirectories)
                    {
                        string ssubNodeText = ssubDirectory.Substring(ssubDirectory.LastIndexOf("\\") + 1);
                        if (!cbDisplayDisposed.Checked && ssubNodeText.Contains("OK"))                  //不显示已理件的文件夹
                            continue;
                        FolderCL ssubFolder = new FolderCL();
                        ssubFolder.FolderName = ssubNodeText;
                        ssubFolder.IsRoot = false;
                        ssubFolder.Path = ssubNodeText;
                        ssubFolder.Level = level + 2;
                        TreeNode ssubNode = new TreeNode();
                        ssubNode.Text = ssubNodeText;
                        ssubNode.Tag = ssubFolder;
                        subNode.Nodes.Add(ssubNode);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 去掉文件，文件夹的只读属性
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="type">true 文件；false 文件夹</param>
        private void RemoveReadOnly(string path, bool type)
        {
            if (type)               //文件
            {
                FileInfo finfo = new FileInfo(path);
                finfo.Attributes = finfo.Attributes ^ FileAttributes.ReadOnly;
            }
            else
            {
                DirectoryInfo dinfo = new DirectoryInfo(path);
                dinfo.Attributes = dinfo.Attributes ^ FileAttributes.ReadOnly;
            }
        }
        //获得当前节点的全路径
        private string GetFullNodePath(TreeNode node, string partPath)
        {
            try
            {
                string totalpath = "";
                FolderCL folder = (FolderCL)node.Tag;
                if (!folder.IsRoot)                 //不是根节点，就递归
                {
                    if (partPath == null || partPath.Length == 0)
                    {
                        totalpath = GetFullNodePath(node.Parent, folder.Path);
                    }
                    else
                    {
                        totalpath = GetFullNodePath(node.Parent, folder.Path + "\\" + partPath);
                    }

                }
                else
                {
                    if (partPath == null || partPath.Length == 0)
                    {
                        totalpath = folder.Path;
                    }
                    else
                    {
                        totalpath = folder.Path + "\\" + partPath;
                    }
                }
                return totalpath;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #region 设置缩略图的拖曳操作
        int clickTimes = 1;
        bool IsCtrlDown = false;                                                    //ctrl键是否按下
        bool IsShiftDown = false;                                                   //shift键是否按下
        List<RasterImageListItem> dragThumbs = new List<RasterImageListItem>();
        Point ClickLocation;

        private void SetBrowserDrag()
        {
            browser.MouseDown += new MouseEventHandler(browser_MouseDown);
            browser.MouseMove += new MouseEventHandler(browser_MouseMove);
            browser.MouseUp += new MouseEventHandler(browser_MouseUp);
            browser.KeyDown += new KeyEventHandler(browser_KeyDown);
            browser.KeyUp += new KeyEventHandler(browser_KeyUp);
        }

        void browser_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                IsCtrlDown = false;
                IsShiftDown = false;
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }

        void browser_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Modifiers == Keys.Control)
                {
                    IsCtrlDown = true;
                }
                else if (e.Modifiers == Keys.Shift)
                {
                    IsShiftDown = true;
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }

        void browser_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                ClickLocation = new Point(e.X, e.Y);
                RasterImageListItem item = browser.HitTest(e.X, e.Y);
                if (item != null)
                {
                    if (dragThumbs.Contains(item))                  //当前位置缩略图已被选中
                    {
                        foreach (RasterImageListItem tt in dragThumbs)
                        {
                            tt.Selected = true;
                        }
                    }
                    else
                    {
                        if (IsCtrlDown)
                        {
                            dragThumbs.Add(item);
                        }
                        else if (IsShiftDown)
                        {
                            dragThumbs.Clear();
                            RasterImageListItemCollection items = browser.SelectedItems;
                            foreach (RasterImageListItem tt in items)
                            {
                                dragThumbs.Add(tt);
                            }
                        }
                        else
                        {
                            dragThumbs.Clear();
                            dragThumbs.Add(item);
                        }
                    }
                    clickTimes = 2;             //可执行拖曳操作
                }
                else
                {
                    dragThumbs.Clear();
                    clickTimes = 1;             //可执行选择操作
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        void browser_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (clickTimes == 2 && e.Button == MouseButtons.Left)  //拖曳
                {
                    Size dragSize = SystemInformation.DragSize;
                    Rectangle rec = new Rectangle(ClickLocation.X - dragSize.Width / 2, ClickLocation.Y - dragSize.Height / 2, dragSize.Width, dragSize.Height);
                    if (!rec.Contains(e.X, e.Y))
                    {
                        List<string> pathes = new List<string>();
                        foreach (RasterImageListItem item in dragThumbs)
                        {
                            PhotoCL p = (PhotoCL)item.Tag;
                            pathes.Add(p.PhotoFullName);
                        }
                        string[] photoPathes = pathes.ToArray();
                        DataObject data = new DataObject(DataFormats.FileDrop, photoPathes);
                        DoDragDrop(data, DragDropEffects.All);
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }

        void browser_MouseUp(object sender, MouseEventArgs e)
        {
            try
            {
                if (clickTimes == 1)
                {
                    dragThumbs.Clear();
                    RasterImageListItemCollection items = browser.SelectedItems;
                    foreach (RasterImageListItem item in items)
                    {
                        dragThumbs.Add(item);
                    }
                }
                //string name = "";
                //foreach (RasterImageListItem item in dragThumbs)
                //{
                //    name += "|" + item.Text;
                //}
                //MessageBox.Show(dragThumbs.Count.ToString()+name);
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        #endregion

        #region 根据商户的助记码变化筛选商户
        //根据商户的助记码变化筛选商户
        private void txtShopZJM_TextChanged(object sender, EventArgs e)
        {
            try
            {
                string zjcode = txtShopZJM.Text;
                DataTable filterDt = AllShop.Clone();
                DataRow[] rows = AllShop.Select("ZJCode like '%" + zjcode + "%'");
                foreach (DataRow r in rows)
                {
                    DataRow nr = filterDt.NewRow();
                    nr.ItemArray = r.ItemArray;
                    filterDt.Rows.Add(nr);
                }
                DataRow[] rows2 = AllShop.Select("ShopName like '%" + zjcode + "%'");
                foreach (DataRow r in rows2)
                {
                    DataRow nr = filterDt.NewRow();
                    nr.ItemArray = r.ItemArray;
                    filterDt.Rows.Add(nr);
                }
                BindShop(filterDt);
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        #endregion

        /// <summary>
        /// 绑定商户
        /// </summary>
        private void BindShop(DataTable shops)
        {
            try
            {
                lbShop.DisplayMember = "ShopName";
                lbShop.ValueMember = "ShopId";
                lbShop.DataSource = shops;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //按enter将内容全部选中
        private void txtShopZJM_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtShopZJM.SelectAll();
            }
        }

        //鼠标滑过就全选
        private void txtShopZJM_MouseEnter(object sender, EventArgs e)
        {
            txtShopZJM.SelectAll();
        }

        /// <summary>
        /// 绑定员工
        /// </summary>
        private void BindUser()
        {
            try
            {
                DataTable dt = bll.GetUsers();
                AllUser = dt;
                /*
                cbUsers.DisplayMember = "UserName";
                cbUsers.ValueMember = "UserId";
                cbUsers.DataSource = dt;
                cbUsers.SelectedValue = UserId;                 //默认的开单员是当前员工*/
                lblStartOrder.Text = dt.Select("UserId=" + UserId).First()["UserName"].ToString();
                lblStartOrder.Tag = UserId;
                SelectedUserId = UserId;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //刷新理件树
        private void tsRefreshPath_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;
                tvExplorer.Nodes.Clear();
                AddTree();
                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                ShowMsg(ex.Message);
            }
        }

        #region 将商户拖曳安装到文件夹上
        private void lbShop_MouseDown(object sender, MouseEventArgs e)
        {
            //获得焦点
            pShop.BackColor = Color.Pink;
            pFolder.BackColor = Color.Empty;
            pPhoto.BackColor = Color.Empty;
        }

        private void lbShop_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (e.Button == MouseButtons.Left)
                {
                    DataRowView row = (DataRowView)lbShop.SelectedItem;
                    if (row == null)
                        return;
                    int shopId = Convert.ToInt32(row["ShopId"]);
                    if (shopId <= 0)
                        return;
                    BLL.CustomerManage.DisposePhotoBLL.ShopCL shop = new MINERP.BLL.CustomerManage.DisposePhotoBLL.ShopCL();
                    shop.ShopId = shopId;
                    shop.ShopName = row["ShopName"].ToString();
                    DataObject data = new DataObject("shop", shop);
                    DoDragDrop(data, DragDropEffects.All);
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        #endregion

        #region 树操作，包括 重命名，拖拉目录等,右键操作
        //F2重命名快捷键
        private void tvExplorer_KeyDown(object sender, KeyEventArgs e)
        {
            /*
            try
            {
                if (tvExplorer.SelectedNode != null)
                {
                    if (e.KeyCode == Keys.F2 && tvExplorer.SelectedNode.Parent != null)                           //重命名
                    {
                        tvExplorer.SelectedNode.BeginEdit();
                    }
                    else if (e.KeyCode == Keys.Delete && tvExplorer.SelectedNode.Parent != null)                  //删除
                    {
                        DelNode();
                    }
                    else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.A)                      //alt+A 新建文件夹
                    {
                        CreateNewFolder();
                    }
                    else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.S && tvExplorer.SelectedNode.Parent != null)  //理件完成
                    {
                        if (cbDisplayDisposed.Checked)
                        {
                            DisposeComplete();
                        }
                        else
                        {
                            DisposeCompleteNoDisplay();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }*/
        }
        //重命名完成
        private void tvExplorer_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            try
            {
                if (e.Label == null)
                {
                    return;
                }
                else if (e.Label.Length == 0)
                {
                    MessageBox.Show("文件夹名字不能为空！", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else if (e.Node.Text == e.Label)
                    return;
                RenameFolder(e.Node, e.Label.Trim());
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        //树右键
        private void tvExplorer_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            try
            {
                if (e.Button == MouseButtons.Right)
                {
                    tvExplorer.SelectedNode = e.Node;
                    if (e.Node.Parent == null)                      //表示是根节点
                        return;
                    e.Node.ContextMenuStrip = contextMenuStrip1;
                }
                else if (e.Button == MouseButtons.Left)             //左键加载文件夹内所有照片
                {
                    tvExplorer.SelectedNode = e.Node;
                    AddPhotoCommon();
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        /// <summary>
        /// 文件夹重命名
        /// </summary>
        /// <param name="node"></param>
        /// <param name="newName"></param>
        private void RenameFolder(TreeNode node, string newName)
        {
            try
            {
                //移动文件夹，等价于完成重命名操作
                string src = GetFullNodePath(node, "");               //原路径
                string dst = src.Substring(0, src.LastIndexOf("\\") + 1) + newName;
                bool r = MoveFile(src, dst, 1 | 2);
                if (r == false)
                {
                    MessageBox.Show("重命名失败，可能是文件名包含了不可用的符号", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                //修改节点tag
                FolderCL folder = (FolderCL)node.Tag;
                folder.FolderName = newName;
                folder.Path = newName;
                node.Text = newName;                                  //显示的文件夹名字
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //节点之间拖曳移动文件夹，拖曳开始
        private void tvExplorer_ItemDrag(object sender, ItemDragEventArgs e)
        {
            try
            {
                TreeNode node = (TreeNode)e.Item;
                if (node.Parent == null)                //根节点不能拖曳
                    return;
                if (node.Text.Trim().EndsWith("OK"))
                {
                    MessageBox.Show("该操作不能用于商户文件夹！", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                DataObject data = new DataObject("TreeNode", node);             //拖曳时传递Node
                DoDragDrop(data, DragDropEffects.All);
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        //拖曳接收
        private void tvExplorer_DragEnter(object sender, DragEventArgs e)
        {
            //if (e.Data.GetDataPresent("TreeNode") || e.Data.GetDataPresent("photo"))
            if (e.Data.GetDataPresent("TreeNode") || e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                preNode = null;
                IsCanExpand = false;
                e.Effect = DragDropEffects.All;
            }
        }
        bool IsCanExpand = false;               //如果鼠标悬停在同一个节点上大于1s，则该节点可以展开
        TreeNode preNode = null;
        private void tvExplorer_DragOver(object sender, DragEventArgs e)
        {
            try
            {
                //if (e.Data.GetDataPresent("TreeNode") || e.Data.GetDataPresent("photo"))
                if (e.Data.GetDataPresent("TreeNode") || e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    Point location = tvExplorer.PointToClient(new Point(e.X, e.Y));
                    TreeNode node = tvExplorer.GetNodeAt(location);
                    if (preNode == null || node != preNode)
                    {
                        timer1.Stop();
                        timer1.Enabled = false;
                        preNode = node;
                        IsCanExpand = false;
                        timer1.Enabled = true;
                        timer1.Start();
                    }
                    if (node != null)
                    {
                        tvExplorer.SelectedNode = node;
                        if (node.Nodes != null && node.Nodes.Count > 0 && IsCanExpand == true)
                        {
                            node.Expand();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            IsCanExpand = true;             //悬停1s以上，就可以展开
        }

        private void tvExplorer_DragDrop(object sender, DragEventArgs e)
        {
            try
            {
                if (e.Data.GetDataPresent("TreeNode"))                              //文件夹的拖动操作
                {
                    TreeNode node = (TreeNode)e.Data.GetData("TreeNode");
                    Point location = tvExplorer.PointToClient(new Point(e.X, e.Y));
                    TreeNode parentNode = tvExplorer.GetNodeAt(location);

                    if (node == parentNode)                                         //如果是节点本身，不操作
                        return;
                    FolderCL srcFolder = (FolderCL)node.Tag;
                    FolderCL parentFolder = (FolderCL)parentNode.Tag;
                    if (srcFolder.Level < parentFolder.Level)                           //源文件夹的层次比目标文件夹层次低，不能移动                    
                        return;
                    //1 移动实物文件夹
                    string src = GetFullNodePath(node, "");                             //源文件夹路径
                    string parentPath = GetFullNodePath(parentNode, "");
                    string folderName = srcFolder.FolderName;
                    string[] subDirectories = Directory.GetDirectories(parentPath);
                    foreach (string subDirectory in subDirectories)
                    {
                        string oldFolderName = subDirectory.Substring(subDirectory.LastIndexOf("\\") + 1);
                        if (oldFolderName == folderName)
                        {
                            if (DialogResult.Yes == MessageBox.Show("目标文件夹中已存在相同名字的文件夹，要重命名再移动吗！", "确定", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                            {
                                folderName = GetNewFolderName(subDirectories.ToList(), 1, folderName);
                                srcFolder.FolderName = folderName;
                                srcFolder.Path = folderName;
                                node.Text = folderName;
                                break;
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                    string tsc = parentPath + "\\" + folderName; //目的路径

                    MoveFile(src, tsc, 1 | 2);
                    //2 修改界面树结构
                    node.Parent.Nodes.Remove(node);
                    parentNode.Nodes.Add(node);
                    ChangeLevel(node, parentFolder.Level);
                }
                else if (e.Data.GetDataPresent("shop"))                             //拖商户来安装
                {
                    if (tvExplorer.SelectedNode != null)
                    {
                        TreeNode node = tvExplorer.SelectedNode;
                        if (node.Text.EndsWith("OK"))
                        {
                            MessageBox.Show("商户已设置！", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                        BLL.CustomerManage.DisposePhotoBLL.ShopCL shop = (BLL.CustomerManage.DisposePhotoBLL.ShopCL)e.Data.GetData("shop");

                        //1 文件夹实物重命名
                        string newName = node.Text + "_" + shop.ShopName + "OK";
                        string src = GetFullNodePath(node, "");
                        string dst = src.Substring(0, src.LastIndexOf("\\") + 1) + newName;
                        MoveFile(src, dst, 1 | 2);

                        //修改界面树结构
                        FolderCL folder = (FolderCL)node.Tag;
                        folder.FolderName = newName;
                        folder.Path = newName;
                        node.Text = newName;
                    }
                }
                //else if (e.Data.GetDataPresent("photo"))                            //拖曳照片
                else if (e.Data.GetDataPresent(DataFormats.FileDrop))                            //拖曳照片
                {
                    if (tvExplorer.SelectedNode != null)
                    {
                        TreeNode node = tvExplorer.SelectedNode;
                        //List<string> pathes = e.Data.GetData("photo") as List<string>;                  //拖曳的所有照片
                        string[] pathes = e.Data.GetData(DataFormats.FileDrop) as string[];                  //拖曳的所有照片
                        string folderPath = GetFullNodePath(node, "");
                        string srcFolderPath = pathes[0].Substring(0, pathes[0].LastIndexOf("\\"));
                        if (folderPath == srcFolderPath)                                                //原始文件夹路径和新路径相同，不作操作
                        {
                            return;
                        }
                        else
                        {
                            //string[] dstFiles = Directory.GetFiles(folderPath, "*.jpg");
                            string[] dstFiles = Directory.GetFiles(folderPath, "*.jpg");
                            List<string> dstFileNames = new List<string>();
                            foreach (string finfo in dstFiles)
                            {
                                dstFileNames.Add(finfo.Substring(finfo.LastIndexOf("\\") + 1));
                            }
                            int sameName = 0;                           //1重命名 2不移动重名的照片
                            string dst = "";
                            //1 移动照片
                            foreach (string photoPath in pathes)
                            {
                                string photoName = photoPath.Substring(photoPath.LastIndexOf("\\") + 1);
                                if (dstFileNames.Contains(photoName))
                                {
                                    if (sameName == 0)
                                    {
                                        if (MessageBox.Show("目标目录中已存在移动照片同名的照片，要重命名吗？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                                        {
                                            sameName = 1;
                                        }
                                        else
                                        {
                                            sameName = 2;
                                        }

                                    }
                                    if (sameName == 1)
                                    {
                                        photoName = GetNewPhotoName(dstFiles.ToList(), 1, photoName.Substring(0, photoName.LastIndexOf(".")), photoName.Substring(photoName.LastIndexOf(".") + 1));
                                        dst = folderPath + "\\" + photoName;
                                    }
                                    else if (sameName == 2)
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    dst = folderPath + photoPath.Substring(photoPath.LastIndexOf("\\"));
                                }
                                MoveFile(photoPath, dst, 1 | 2);
                            }
                            //2 展开当前目录的照片
                            AddPhotoCommon();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        /// <summary>
        /// 修改节点及其所有子节点的层次
        /// </summary>
        /// <param name="node"></param>
        /// <param name="parentLevel"></param>
        private void ChangeLevel(TreeNode node, int parentLevel)
        {
            try
            {
                FolderCL folder = (FolderCL)node.Tag;
                folder.Level = parentLevel + 1;
                if (node.Nodes == null || node.Nodes.Count == 0)
                    return;
                else
                {
                    foreach (TreeNode subNode in node.Nodes)
                    {
                        ChangeLevel(subNode, folder.Level);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 新建文件夹时取得新建文件夹的名字(为防止重名)
        /// </summary>
        /// <param name="node"></param>
        /// <param name="x"></param>
        /// <returns></returns>
        private string GetNewFolderName(TreeNode node, int x)
        {
            string name = "新建文件夹";
            if (x > 1)
                name += " (" + x.ToString() + ")";
            foreach (TreeNode subNode in node.Nodes)
            {
                if (subNode.Text == name)
                {
                    x++;
                    name = GetNewFolderName(node, x);
                    break;
                }
            }
            return name;
        }
        /// <summary>
        /// 重命名文件夹时，防止文件夹重名的操作
        /// </summary>
        /// <param name="folders"></param>
        /// <param name="x"></param>
        /// <param name="folderName"></param>
        /// <returns></returns>
        private string GetNewFolderName(List<string> folders, int x, string folderName)
        {
            string newFolderName = folderName;
            if (x > 1)
            {
                newFolderName = folderName + " (" + x.ToString() + ")";
            }
            foreach (string f in folders)
            {
                if (f.Substring(f.LastIndexOf("\\") + 1) == newFolderName)
                {
                    x++;
                    newFolderName = GetNewFolderName(folders, x, folderName);
                    break;
                }
            }
            return newFolderName;
        }
        /// <summary>
        /// 重命名照片时，防止照片名重复，作的取名操作(如果名字重复，就+1)
        /// </summary>
        /// <param name="photos"></param>
        /// <param name="x"></param>
        /// <param name="photoName"></param>
        /// <param name="pattern"></param>
        /// <returns></returns>
        private string GetNewPhotoName(List<string> photos, int x, string photoName, string pattern)
        {
            string newPhotoName = "";
            if (x > 1)
            {
                newPhotoName = photoName + " (" + x.ToString() + ")." + pattern;
            }
            else
            {
                newPhotoName = photoName + "." + pattern;
            }
            foreach (string p in photos)
            {
                if (p.Substring(p.LastIndexOf("\\") + 1) == newPhotoName)
                {
                    x++;
                    newPhotoName = GetNewPhotoName(photos, x, photoName, pattern);
                    break;
                }
            }
            return newPhotoName;
        }
        //重命名
        private void tsRename_Click(object sender, EventArgs e)
        {
            try
            {
                tvExplorer.SelectedNode.BeginEdit();
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        //新建文件夹
        private void tsCreateNew_Click(object sender, EventArgs e)
        {
            try
            {
                CreateNewFolder();
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        /// <summary>
        /// 新建文件夹公共操作
        /// </summary>
        private void CreateNewFolder()
        {
            try
            {
                TreeNode node = tvExplorer.SelectedNode;
                FolderCL folder = (FolderCL)node.Tag;
                string name = GetNewFolderName(node, 1);                    //为防止重名，进行了处理
                //1 新建实物文件夹 
                string path = GetFullNodePath(node, "") + "\\" + name;
                Directory.CreateDirectory(path);

                //修改界面结构
                FolderCL newFolder = new FolderCL();
                newFolder.FolderName = name;
                newFolder.IsRoot = false;
                newFolder.Level = folder.Level + 1;
                newFolder.Path = name;
                TreeNode newNode = new TreeNode();
                newNode.Text = name;
                newNode.Tag = newFolder;
                node.Nodes.Add(newNode);
                if (!node.IsExpanded)
                    node.Expand();
                newNode.BeginEdit();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //删除文件夹
        private void tsDelFolder_Click(object sender, EventArgs e)
        {
            try
            {
                DelNode();
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        /// <summary>
        /// 删除文件夹的公共操作
        /// </summary>
        private void DelNode()
        {
            try
            {
                if (DialogResult.Yes != MessageBox.Show("确定要删除选中的文件夹吗?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                {
                    return;
                }
                //1 删除实物文件夹
                TreeNode node = tvExplorer.SelectedNode;
                string path = GetFullNodePath(node, "");
                DirectoryInfo dinfo = new DirectoryInfo(path);
                dinfo.Attributes = FileAttributes.Normal;                   //去掉只读，便于删除
                //Directory.Delete(path, true);
                DelDirectoryRecursive(path);

                //修改界面结构
                node.Parent.Nodes.Remove(node);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 递归删除文件夹
        /// </summary>
        /// <param name="path"></param>
        private void DelDirectoryRecursive(string path)
        {
            try
            {
                string[] subDirectories = Directory.GetDirectories(path);
                string[] subFiles = Directory.GetFiles(path);
                foreach (string subFile in subFiles)                    //删除子文件
                {
                    if (!DelFile(subFile))
                    {
                        FileInfo finfo = new FileInfo(subFile);
                        finfo.Attributes = FileAttributes.Normal;       //去掉只读属性，再试一次
                        DelFile(subFile);
                    }
                }
                foreach (string subDirectory in subDirectories)
                {
                    DelDirectoryRecursive(subDirectory);
                }
                RemoveDirectory(path);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //理件完成
        private void tsLJComplete_Click(object sender, EventArgs e)
        {
            try
            {
                if (cbDisplayDisposed.Checked)
                {
                    DisposeComplete();
                }
                else
                {
                    DisposeCompleteNoDisplay();
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        /// <summary>
        /// 理件完成的公共操作
        /// </summary>
        private void DisposeComplete()
        {
            try
            {
                //先判断文件夹是否已存在于商户文件夹中
                TreeNode node = tvExplorer.SelectedNode;
                if (node.Text.Trim().EndsWith("OK"))
                {
                    MessageBox.Show("该操作不能用于商户文件夹！", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                DataRowView shop = (DataRowView)lbShop.SelectedItem;
                if (shop == null)
                {
                    MessageBox.Show("请先在左边列表中选中商户！", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                //弹出对话框，选择商户
                FrmSetShop frm = new FrmSetShop();
                frm.frm = this;
                frm.ShopDt = AllShop;
                frm.ShopId = Convert.ToInt32(shop["ShopId"]);
                if (DialogResult.OK == frm.ShowDialog())
                {
                    string shopName = SelectedShopName + "OK";                              //结尾加上OK是为了 区分真正的已完成整理的文件夹
                    lbShop.SelectedValue = SelectedShopId;
                    //1 判断商户文件夹是否存在，如果不存在，就创建
                    TreeNode root = tvExplorer.Nodes[0];                 //根节点
                    FolderCL folder = (FolderCL)root.Tag;
                    string rootPath = folder.Path;
                    string[] directories = Directory.GetDirectories(rootPath);
                    TreeNode shopNode = null;
                    foreach (TreeNode n in root.Nodes)
                    {
                        if (n.Text == shopName)
                        {
                            shopNode = n;
                            break;
                        }
                    }
                    if (shopNode == null)
                    {
                        string path = GetFullNodePath(root, "") + "\\" + shopName;
                        Directory.CreateDirectory(path);
                        FolderCL subFolder = new FolderCL();
                        subFolder.FolderName = shopName;
                        subFolder.IsRoot = false;
                        subFolder.Level = 2;
                        subFolder.Path = shopName;
                        shopNode = new TreeNode();
                        shopNode.Text = shopName;
                        shopNode.Tag = subFolder;
                        root.Nodes.Add(shopNode);
                    }
                    //2 将指定的文件夹剪切到商户文件夹中
                    string src = GetFullNodePath(node, "");
                    string folderName = node.Text;
                    string parentPath = GetFullNodePath(shopNode, "");
                    string[] subDirectories = Directory.GetDirectories(parentPath);
                    foreach (string subDirectory in subDirectories)
                    {
                        if (subDirectory.Substring(subDirectory.LastIndexOf("\\") + 1) == folderName)
                        {
                            MessageBox.Show("目标文件夹中已存在相同名字的文件夹，请先重命名！", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    string tsc = GetFullNodePath(shopNode, "") + "\\" + src.Substring(src.LastIndexOf("\\") + 1);
                    DirectoryInfo dinfo = new DirectoryInfo(src);
                    dinfo.Attributes = FileAttributes.Normal;                   //去掉可能的只读属性
                    //bool r = MoveFile(src, tsc, 2);
                    Directory.Move(src, tsc);
                    node.Parent.Nodes.Remove(node);
                    shopNode.Nodes.Add(node);
                    ChangeLevel(node, 2);
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message + "(请查看移动的文件夹是否是打开的)");
            }
        }
        /// <summary>
        /// 理件完成的公共操作，不显示商户文件夹
        /// </summary>
        private void DisposeCompleteNoDisplay()
        {
            try
            {
                //先判断文件夹是否已存在于商户文件夹中
                TreeNode node = tvExplorer.SelectedNode;
                if (node.Text.Trim().EndsWith("OK"))
                {
                    MessageBox.Show("该操作不能用于商户文件夹！", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                DataRowView shop = (DataRowView)lbShop.SelectedItem;
                if (shop == null)
                {
                    MessageBox.Show("请先在左边列表中选中商户！", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                //弹出对话框，选择商户
                FrmSetShop frm = new FrmSetShop();
                frm.frm = this;
                frm.ShopDt = AllShop;
                frm.ShopId = Convert.ToInt32(shop["ShopId"]);
                if (DialogResult.OK == frm.ShowDialog())
                {
                    string shopName = SelectedShopName + "OK";                              //结尾加上OK是为了 区分真正的已完成整理的文件夹
                    lbShop.SelectedValue = SelectedShopId;
                    //1 判断商户文件夹是否存在，如果不存在，就创建
                    bool isExist = false;                                //商户文件夹是否已存在
                    TreeNode root = tvExplorer.Nodes[0];                 //根节点
                    string rootPath = GetFullNodePath(root, "");
                    string[] directories = Directory.GetDirectories(rootPath);
                    foreach (string directory in directories)
                    {
                        string dname = directory.Substring(directory.LastIndexOf("\\") + 1);
                        if (dname == shopName)
                        {
                            isExist = true;
                            break;
                        }
                    }
                    string path = GetFullNodePath(root, "") + "\\" + shopName;
                    if (isExist == false)
                    {
                        Directory.CreateDirectory(path);
                    }
                    //2 将指定的文件夹剪切到商户文件夹中
                    string src = GetFullNodePath(node, "");
                    string folderName = node.Text;
                    string[] subDirectories = Directory.GetDirectories(path);
                    foreach (string subDirectory in subDirectories)
                    {
                        if (subDirectory.Substring(subDirectory.LastIndexOf("\\") + 1) == folderName)
                        {
                            MessageBox.Show("目标文件夹中已存在相同名字的文件夹，请先重命名！", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    string tsc = path + "\\" + src.Substring(src.LastIndexOf("\\") + 1);
                    //bool r = MoveFile(src, tsc, 2);
                    Directory.Move(src, tsc);
                    node.Parent.Nodes.Remove(node);
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message + "(请查看移动的文件夹是否是打开的)");
            }
        }
        /// <summary>
        /// 判断文件夹是否已保存在商户文件夹中(明天继续)
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private bool IsInShopFolder(TreeNode node)
        {
            bool isIn = false;
            if (node.Parent == null)
            {
                isIn = false;
            }
            else
            {
                TreeNode parentNode = node.Parent;
                if (parentNode.Text.EndsWith("OK"))
                {
                    isIn = true;
                }
                else
                {
                    isIn = IsInShopFolder(parentNode);
                }
            }
            return isIn;
        }

        //打开文件夹
        private void tsOpenFolder_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFolderCommon();
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }

        /// <summary>
        /// 打开文件夹的公共操作
        /// </summary>
        private void OpenFolderCommon()
        {
            try
            {
                TreeNode node = tvExplorer.SelectedNode;
                if (node == null)
                    return;
                string path = GetFullNodePath(node, "");
                OpenFolder(IntPtr.Zero, new StringBuilder("open"), new StringBuilder("explorer.exe"),
                                             new StringBuilder(path), new StringBuilder(string.Empty), 1);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        /// <summary>
        /// 显示信息
        /// </summary>
        /// <param name="msg"></param>
        private void ShowMsg(string msg)
        {
            MessageBox.Show(msg, "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        #region 页面快捷键
        //页面快捷键
        private void FrmDisposeMain_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                //1,2,3分别对应3个不同部分的焦点
                if (e.KeyCode == Keys.D1)
                {
                    lbShop.Focus();
                    SetFocus(1);
                }
                else if (e.KeyCode == Keys.D2)
                {
                    tvExplorer.Focus();
                    SetFocus(2);
                }
                else if (e.KeyCode == Keys.D3)
                {
                    gcPhotoHW.Focus();
                    SetFocus(3);
                }
                else if (e.KeyCode == Keys.F2)                           //重命名
                {
                    SetFocus(2);
                    tvExplorer.Focus();
                    if (tvExplorer.SelectedNode != null && tvExplorer.SelectedNode.Parent != null)
                        tvExplorer.SelectedNode.BeginEdit();
                }
                else if (e.KeyCode == Keys.Delete)                  //删除
                {
                    SetFocus(2);
                    tvExplorer.Focus();
                    if (tvExplorer.SelectedNode.Parent != null)
                        DelNode();
                }
                else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.A)                      //alt+A 新建文件夹
                {
                    SetFocus(2);
                    tvExplorer.Focus();
                    CreateNewFolder();
                }
                else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.S)  //理件完成
                {
                    SetFocus(2);
                    tvExplorer.Focus();
                    if (tvExplorer.SelectedNode.Parent != null)
                    {
                        if (cbDisplayDisposed.Checked)
                        {
                            DisposeComplete();
                        }
                        else
                        {
                            DisposeCompleteNoDisplay();
                        }
                    }
                }
                else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.D)
                {
                    SetFocus(2);
                    tvExplorer.Focus();
                    OpenFolderCommon();
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        /// <summary>
        /// 设置焦点
        /// </summary>
        /// <param name="type"></param>
        private void SetFocus(int type)
        {
            switch (type)
            {
                case 1:
                    pShop.BackColor = Color.Pink;
                    pFolder.BackColor = Color.Empty;
                    pPhoto.BackColor = Color.Empty;
                    break;
                case 2:
                    pShop.BackColor = Color.Empty;
                    pFolder.BackColor = Color.Pink;
                    pPhoto.BackColor = Color.Empty;
                    break;
                case 3:
                    pShop.BackColor = Color.Empty;
                    pFolder.BackColor = Color.Empty;
                    pPhoto.BackColor = Color.Pink;
                    break;
            }
        }

        //关闭，展开商户选择
        private void tsCloseShop_Click(object sender, EventArgs e)
        {
            SetCloseShop();
        }
        private void SetCloseShop()
        {
            if (!spcSecond.Panel1Collapsed)             //商户选择本身是展开的
            {
                spcSecond.Panel1Collapsed = true;       //点击后关闭
                tsCloseShop.Text = "展开选择商户&R";
                tsCloseShop.Image = Properties.Resources.OpenDirectory;
            }
            else
            {
                spcSecond.Panel1Collapsed = false;      //点击后展开
                tsCloseShop.Text = "关闭选择商户&R";
                tsCloseShop.Image = Properties.Resources.close;
            }
        }
        #endregion

        #region 照片的操作
        //参数
        public string photoNewName = "";                                //照片重命名的名字`

        //读文件夹内的照片信息
        private void tvExplorer_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                AddPhotoCommon();
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        /// <summary>
        /// 加载文件夹内照片的公共操作
        /// </summary>
        private void AddPhotoCommon()
        {
            try
            {
                TreeNode node = tvExplorer.SelectedNode;
                if (prePhotoNode != null && prePhotoNode == node && ExAddPhoto == false)   //前一个节点和当前节点相同，表示已加载过照片，本次不再加载
                    return;
                else
                {
                    prePhotoNode = node;
                }
                gcPhotoHW.DataSource = null;
                gcPhotoHW.RefreshDataSource();
                if (node == null)
                    return;
                StandardUnit = "";                                  //裁片的标准单位设为空
                string path = GetFullNodePath(node, "");            //选中文件夹的总路径
                string[] files1 = Directory.GetFiles(path, "*.jpg");
                string[] files2 = Directory.GetFiles(path, "*.jpeg");
                string[] files = files1.Concat(files2).ToArray();
                if (files != null && files.Length > 0)
                {
                    Cursor = Cursors.WaitCursor;
                    List<PhotoCL> photos = new List<PhotoCL>();
                    RasterCodecs.Startup();
                    RasterCodecs codecs = new RasterCodecs();
                    foreach (string f in files)
                    {
                        CodecsImageInfo img = codecs.GetInformation(f, true);
                        PhotoCL p = new PhotoCL();
                        p.DPI = img.XResolution;
                        p.FileName = f.Substring(f.LastIndexOf("\\") + 1);
                        p.PhotoFullName = f;
                        p.HeightPix = img.Height;
                        p.WidthPix = img.Width;
                        p.Height = (double)img.Height / p.DPI;
                        p.Width = (double)img.Width / p.DPI;
                        p.HWcm = string.Format("{0:0.##}", p.Height * 2.54) + "×" + string.Format("{0:0.##}", p.Width * 2.54);
                        p.HWin = string.Format("{0:0.##}", p.Height) + "×" + string.Format("{0:0.##}", p.Width);
                        photos.Add(p);
                        img.Dispose();
                    }
                    codecs.Dispose();
                    RasterCodecs.Shutdown();

                    if (DisplayMode == true)
                    {
                        pPhotoDetail.Controls.Clear();
                        pPhotoDetail.Controls.Add(gcPhotoHW);
                        DisplayMode = false;
                    }

                    gcPhotoHW.DataSource = photos;
                    gcPhotoHW.RefreshDataSource();
                    if (tsExpand.Text.Contains("合拢"))
                    {
                        gvPhotoHW.ExpandAllGroups();
                    }
                    SetPhotoGroup();
                    Cursor = Cursors.Default;
                }
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                throw ex;
            }
        }

        /// <summary>
        /// 照片按尺寸分组信息
        /// </summary>
        private void SetPhotoGroup()
        {
            try
            {
                lbPhotoGroup.Items.Clear();
                List<PhotoCL> photos = gcPhotoHW.DataSource as List<PhotoCL>;
                lbPhotoGroup.Items.Add("照片总数量：" + photos.Count.ToString());
                Dictionary<string, int> groups = new Dictionary<string, int>();
                foreach (PhotoCL p in photos)
                {
                    if (groups.Keys.Contains(p.HWcm))
                    {
                        groups[p.HWcm]++;
                    }
                    else
                    {
                        groups.Add(p.HWcm, 1);
                    }
                }
                foreach (KeyValuePair<string, int> pair in groups)
                {
                    lbPhotoGroup.Items.Add(pair.Key + " 数量：" + pair.Value.ToString());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //重名名照片
        private void tsRenamePhoto_Click(object sender, EventArgs e)
        {
            try
            {
                SetFocus(3);
                gcPhotoHW.Focus();
                PhotoRenameCommon();
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        /// <summary>
        /// 重命名照片公共操作
        /// </summary>
        private void PhotoRenameCommon()
        {
            try
            {
                int[] indexes = gvPhotoHW.GetSelectedRows();
                List<int> indexes2 = new List<int>();
                foreach (int i in indexes)
                {
                    if (i >= 0)
                        indexes2.Add(i);
                }
                if (indexes2.Count > 0)
                {
                    FrmModifyName frm = new FrmModifyName();
                    frm.frm = this;
                    string PhotoOldName = gvPhotoHW.GetRowCellValue(indexes[0], "FileName").ToString();
                    frm.PhotoOldName = PhotoOldName;
                    if (DialogResult.OK == frm.ShowDialog())
                    {
                        //取得所有照片的原始路径
                        List<string> oldPhotos = new List<string>();
                        List<PhotoCL> photos = gcPhotoHW.DataSource as List<PhotoCL>;
                        foreach (PhotoCL p in photos)
                        {
                            oldPhotos.Add(p.PhotoFullName);
                        }

                        string newName = "";
                        string photoNewNamePart = photoNewName.Substring(0, photoNewName.LastIndexOf("."));
                        string photoNewNamePattern = photoNewName.Substring(photoNewName.LastIndexOf(".") + 1);
                        foreach (int index in indexes2)
                        {
                            PhotoCL photo = gvPhotoHW.GetRow(index) as PhotoCL;
                            //1 修改实物照片的名字
                            string src = photo.PhotoFullName;
                            newName = GetNewPhotoName(oldPhotos, 1, photoNewNamePart, photoNewNamePattern);
                            string dst = src.Substring(0, src.LastIndexOf("\\") + 1) + newName;
                            MoveFile(src, dst, 1 | 2);

                            //2 修改界面显示
                            photo.FileName = newName;
                            photo.PhotoFullName = dst;

                            //3 保存新名字，下次循环使用
                            oldPhotos.Add(dst);
                        }
                        gcPhotoHW.RefreshDataSource();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //删除照片
        private void tsDelPhoto_Click(object sender, EventArgs e)
        {
            try
            {
                SetFocus(3);
                gcPhotoHW.Focus();
                DelPhotoCommom();
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        /// <summary>
        /// 删除照片的公共操作
        /// </summary>
        private void DelPhotoCommom()
        {
            try
            {
                int[] indexes = gvPhotoHW.GetSelectedRows();
                List<int> indexes2 = new List<int>();
                foreach (int i in indexes)
                {
                    if (i >= 0)
                    {
                        indexes2.Add(i);
                    }
                }
                if (indexes2.Count > 0)
                {
                    if (DialogResult.OK != MessageBox.Show("确定要删除选中的照片吗?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
                    {
                        return;
                    }
                    string path = "";
                    foreach (int index in indexes2)
                    {
                        path = gvPhotoHW.GetRowCellValue(index, "PhotoFullName").ToString();
                        try
                        {
                            File.Delete(path);
                        }
                        catch
                        {
                            FileInfo finfo = new FileInfo(path);                    //去掉文件的只读属性
                            finfo.Attributes = FileAttributes.Normal;
                            File.Delete(path);
                        }
                    }
                    ExAddPhoto = true;              //强制刷新
                    AddPhotoCommon();
                    ExAddPhoto = false;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //修改尺寸
        private void tsModifyHW_Click(object sender, EventArgs e)
        {
            try
            {
                SetFocus(3);
                gcPhotoHW.Focus();
                ModifyHWComman();
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }
        /// <summary>
        /// 修改照片尺寸的公共操作
        /// </summary>
        private void ModifyHWComman()
        {
            try
            {
                int[] indexes = gvPhotoHW.GetSelectedRows();
                List<int> indexes2 = new List<int>();
                foreach (int i in indexes)
                {
                    if (i >= 0)
                        indexes2.Add(i);
                }
                if (indexes2.Count > 0)
                {
                    FrmModifyHW frm = new FrmModifyHW();
                    frm.frm = this;
                    if (StandardUnit.Length == 0)
                    {
                        PhotoCL photo = gvPhotoHW.GetRow(indexes[0]) as PhotoCL;
                        frm.OldHeight = photo.Height;
                        frm.OldWidth = photo.Width;
                    }
                    else
                    {
                        frm.OldUnit = StandardUnit;
                        frm.OldHeight = StandardHeight;
                        frm.OldWidth = StandardWidth;
                    }
                    int oldPixH = 0;                        //原来的像素高
                    int oldPixW = 0;                        //原来的像素宽
                    int newPixH = 0;
                    int newPixW = 0;
                    if (DialogResult.OK == frm.ShowDialog())
                    {
                        RasterCodecs.Startup();
                        RasterCodecs codecs = new RasterCodecs();
                        CropCommand command = new CropCommand();
                        foreach (int index in indexes2)
                        {
                            PhotoCL p = gvPhotoHW.GetRow(index) as PhotoCL;
                            if (p.Height <= NewHeight && p.Width <= NewWidth)           //小于或等于新高宽就不作操作
                            {
                                continue;
                            }
                            else
                            {
                                string path = p.PhotoFullName;
                                oldPixH = p.HeightPix;                                  //原来的像素
                                oldPixW = p.WidthPix;
                                newPixH = Convert.ToInt32(NewHeight * p.DPI);           //新像素
                                newPixW = Convert.ToInt32(NewWidth * p.DPI);
                                command.Rectangle = new Rectangle((oldPixW - newPixW) / 2, 0, newPixW, newPixH);
                                RasterImage img = codecs.Load(path);
                                command.Run(img);                   //裁照片
                                try
                                {
                                    codecs.Save(img, path, RasterImageFormat.Jpeg, 24);
                                }
                                catch
                                {
                                    FileInfo finfo = new FileInfo(path);                    //去掉只读属性，再试一次
                                    finfo.Attributes = FileAttributes.Normal;
                                    codecs.Save(img, path, RasterImageFormat.Jpeg, 24);
                                }
                            }
                        }
                        codecs.Dispose();
                        RasterCodecs.Shutdown();
                        //重新加载
                        ExAddPhoto = true;                      //强制重新加载文件夹内的照片
                        AddPhotoCommon();
                        ExAddPhoto = false;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        GridHitInfo hitInfo = null;
        //拖曳照片，实现移动到不同的文件夹
        private void gvPhotoHW_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                hitInfo = gvPhotoHW.CalcHitInfo(e.Location);
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }

        private void gvPhotoHW_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (e.Button == MouseButtons.Left && hitInfo != null && (hitInfo.HitTest == GridHitTest.RowCell || hitInfo.HitTest == GridHitTest.Row || hitInfo.HitTest == GridHitTest.RowEdge))
                {
                    Size size = SystemInformation.DragSize;
                    Rectangle rec = new Rectangle(hitInfo.HitPoint.X - size.Width / 2, hitInfo.HitPoint.Y - size.Height / 2, size.Width, size.Height);
                    if (!rec.Contains(e.X, e.Y) && hitInfo.HitTest != GridHitTest.RowIndicator)
                    {
                        int[] indexes = gvPhotoHW.GetSelectedRows();
                        if (indexes == null || indexes.Count() == 0)
                            return;
                        List<string> pathes = new List<string>();
                        foreach (int index in indexes)
                        {
                            pathes.Add(gvPhotoHW.GetRowCellValue(index, "PhotoFullName").ToString());
                        }
                        //DataObject data = new DataObject("photo", pathes);
                        string[] photoPathes = pathes.ToArray();
                        DataObject data2 = new DataObject(DataFormats.FileDrop, photoPathes);
                        DoDragDrop(data2, DragDropEffects.All);
                        hitInfo = null;
                    }
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }

        //双击筛选出符合高宽的照片
        private void gvPhotoHW_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            try
            {
                if (e.Clicks == 2 && (e.Column.FieldName == "HWcm" || e.Column.FieldName == "HWin"))
                {
                    string standardUnit = e.Column.FieldName;                           //修改高宽的标准单位
                    double standardH = Convert.ToDouble(gvPhotoHW.GetRowCellValue(e.RowHandle, "Height"));
                    double standardW = Convert.ToDouble(gvPhotoHW.GetRowCellValue(e.RowHandle, "Width"));
                    StandardUnit = standardUnit;
                    StandardHeight = standardH;
                    StandardWidth = standardW;
                    //修改背景色
                    List<PhotoCL> photos = gcPhotoHW.DataSource as List<PhotoCL>;
                    for (int i = 0; i < photos.Count; i++)
                    {
                        if (photos[i].Height != standardH && photos[i].Width != standardW)
                        {
                            photos[i].Rank = -1;                            //-1表示不符合标准高宽
                        }
                        else
                        {
                            photos[i].Rank = 0;                             //0表示符合标准高宽  
                        }
                    }

                    DevExpress.XtraGrid.Columns.GridColumnSortInfoCollection sortColumns = gvPhotoHW.SortInfo;
                    gvPhotoHW.ClearSorting();
                    if (gvPhotoHW.GroupCount == 0)
                        sortColumns.Clear();
                    GridColumnSortInfo sortColumn = new GridColumnSortInfo(gcRank, DevExpress.Data.ColumnSortOrder.Ascending);
                    sortColumn.Column = gcRank;
                    sortColumn.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
                    gvPhotoHW.SortInfo.Add(sortColumn);
                    gcPhotoHW.RefreshDataSource();
                }
            }
            catch (Exception ex)
            {
                ShowMsg(ex.Message);
            }
        }

        //根据尺寸筛选照片
        private void gvPhotoHW_RowStyle(object sender, RowStyleEventArgs e)
        {
            try
            {
                if (Convert.ToInt32(gvPhotoHW.GetRowCellValue(e.RowHandle, "Rank")) == -1)
                {
                    e.Appearance.BackColor = Color.Pink;
                    e.Appearance.BackColor = Color.Pink;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //展开，合拢照片分组
        private void tsExpand_Click(object sender, EventArgs e)
        {
            if (gvPhotoHW.GroupCount > 0)
            {
                SetFocus(3);
                string txt = tsExpand.Text;
                if (txt.Contains("展开"))
                {
                    gvPhotoHW.ExpandAllGroups();
                    tsExpand.Text = "合拢&V";
                }
                else if (txt.Contains("合拢"))
                {
                    gvPhotoHW.CollapseAllGroups();
                    tsExpand.Text = "展开&V";
                }
            }
        }
        //照片列表与缩略图之间切换
        private void tsExchange_Click(object sender, EventArgs e)
        {
            try
            {
                if (gcPhotoHW.DataSource == null)
                    return;
                Cursor = Cursors.WaitCursor;
                List<PhotoCL> photos = gcPhotoHW.DataSource as List<PhotoCL>;
                List<PhotoCL> selectedPhotos = new List<PhotoCL>();
                if (DisplayMode)                    //当前显示的是缩略图
                {
                    RasterImageListItemCollection selectedThumbs = browser.SelectedItems;
                    foreach (RasterImageListItem item in selectedThumbs)
                    {
                        selectedPhotos.Add((PhotoCL)item.Tag);
                    }
                    pPhotoDetail.Controls.Clear();
                    pPhotoDetail.Controls.Add(gcPhotoHW);
                    gvPhotoHW.ClearSelection();
                    for (int i = 0; i < gvPhotoHW.RowCount; i++)
                    {
                        PhotoCL pp = (PhotoCL)gvPhotoHW.GetRow(i);
                        if (selectedPhotos.Contains(pp))
                            gvPhotoHW.SelectRow(i);
                    }
                    DisplayMode = false;
                }
                else                                //当前显示的是列表
                {
                    int[] indexes = gvPhotoHW.GetSelectedRows();        //当前选中的照片
                    foreach (int index in indexes)
                    {
                        PhotoCL pp = gvPhotoHW.GetRow(index) as PhotoCL;
                        selectedPhotos.Add(pp);
                    }
                    browser.Items.Clear();
                    RasterCodecs.Startup();
                    RasterCodecs codecs = new RasterCodecs();
                    RasterImage img = null;
                    RasterImageListItem item = null;
                    dragThumbs.Clear();                     //拖曳操作选中的照片
                    foreach (PhotoCL p in photos)
                    {
                        try
                        {
                            img = codecs.ReadStamp(p.PhotoFullName, 1);
                            if (img == null)
                            {
                                img = codecs.Load(p.PhotoFullName);
                            }
                            item = new RasterImageListItem(img, 1, p.FileName);
                            p.Thumb = item;
                            item.Tag = p;
                            browser.Items.Add(p.Thumb);
                            if (selectedPhotos.Contains(p))
                            {
                                dragThumbs.Add(item);
                                item.Selected = true;
                            }
                        }
                        catch { continue; }             //没有缩略图就不加载
                    }
                    RasterCodecs.Shutdown();
                    //加载缩略图
                    browser.Dock = DockStyle.Fill;
                    browser.SelectionMode = RasterImageListSelectionMode.Multi;

                    pPhotoDetail.Controls.Clear();
                    pPhotoDetail.Controls.Add(browser);
                    DisplayMode = true;
                }
                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                ShowMsg(ex.Message);
            }
        }
        /// <summary>
        /// 清空缩略图容器中所有的缩略图
        /// </summary>
        private void BrowserClear()
        {
            try
            {
                if (browser.Items.Count > 0)
                {
                    for (int j = browser.Items.Count - 1; j >= 0; j--)
                    {
                        browser.Items.RemoveAt(j);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        //文件夹操作获得焦点
        private void tvExplorer_MouseDown(object sender, MouseEventArgs e)
        {
            pShop.BackColor = Color.Empty;
            pFolder.BackColor = Color.Pink;
            pPhoto.BackColor = Color.Empty;
        }
        //照片操作获得焦点
        private void gcPhotoHW_MouseDown(object sender, MouseEventArgs e)
        {
            pShop.BackColor = Color.Empty;
            pFolder.BackColor = Color.Empty;
            pPhoto.BackColor = Color.Pink;
        }

        //是否显示已理件发生改变
        private void cbDisplayDisposed_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;
                tvExplorer.Nodes.Clear();
                AddTree();
                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                ShowMsg(ex.Message);
            }
        }

        //保存整理
        private void tsSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!CheckIsOkExist())
                {
                    return;
                }
                Cursor = Cursors.WaitCursor;
                FrmSetUser frm = new FrmSetUser();
                frm.UserDt = AllUser;
                frm.UserId = SelectedUserId;
                frm.frm = this;
                if (DialogResult.OK == frm.ShowDialog())
                {
                    lblStartOrder.Text = SelectedUserName;
                    lblStartOrder.Tag = SelectedUserId;
                    string startOrderUserName = lblStartOrder.Text.Trim();              //开单员名字
                    string startOrderUserPath = StartOrderTotalPath + "\\" + startOrderUserName;        //开单员的开单路径
                    if (!Directory.Exists(startOrderUserPath))                          //如果该开单员的开单路径还不存在，就新建
                    {
                        Directory.CreateDirectory(startOrderUserPath);
                    }
                    string[] subDirectories = Directory.GetDirectories(DisposeTotalPath);
                    string shopOkName = "";               //商户+OK名
                    string shopName = "";               //商户名
                    string shopPath = "";               //商户开单路径
                    foreach (string subDirectory in subDirectories)
                    {
                        if (subDirectory.EndsWith("OK"))                //OK结束，表示是已理件文件夹
                        {
                            shopOkName = subDirectory.Substring(subDirectory.LastIndexOf("\\") + 1);
                            shopName = shopOkName.Substring(0, shopOkName.LastIndexOf("OK"));       //商户名
                            shopPath = startOrderUserPath + "\\" + shopName;
                            if (!Directory.Exists(shopPath))                    //商户不存在，就创建
                            {
                                Directory.CreateDirectory(shopPath);
                            }
                            if (!Directory.Exists(shopPath + "\\已开单"))       //"已开单"不存在，就创建
                            {
                                Directory.CreateDirectory(shopPath + "\\已开单");
                            }
                            string[] ssubDirectories = Directory.GetDirectories(subDirectory);
                            string[] oldCtmPathes = Directory.GetDirectories(shopPath);     //原有的客户
                            List<string> oldCtmNames = new List<string>();
                            foreach (string cp in oldCtmPathes)
                            {
                                oldCtmNames.Add(cp.Substring(cp.LastIndexOf("\\") + 1));
                            }

                            int sameName = 0;                                   //1重命名后再移动 2不重命名，放弃移动
                            string currentCtmName = "";
                            foreach (string ssubDirectory in ssubDirectories)   //将所有整理好的客户文件夹剪切到目标商户下
                            {
                                //r = MoveFile(ssubDirectory, shopPath + "\\" + ssubDirectory.Substring(ssubDirectory.LastIndexOf("\\") + 1), 1 | 2);
                                currentCtmName = ssubDirectory.Substring(ssubDirectory.LastIndexOf("\\") + 1);
                                if (oldCtmNames.Contains(currentCtmName))
                                {
                                    if (sameName == 0)
                                    {
                                        if (DialogResult.Yes == MessageBox.Show("等待开单中已存同名的客人名，要自动重命名再移动吗？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                                        {
                                            sameName = 1;
                                        }
                                        else
                                        {
                                            sameName = 2;
                                        }
                                    }
                                    if (sameName == 1)
                                    {
                                        currentCtmName = GetNewFolderName(oldCtmPathes.ToList(), 1, currentCtmName);
                                    }
                                    else if (sameName == 2)
                                    {
                                        continue;
                                    }
                                }
                                Directory.Move(ssubDirectory, shopPath + "\\" + currentCtmName);
                            }
                            //删除原商户OK目录
                            Directory.Delete(subDirectory);
                        }
                    }
                    Cursor = Cursors.Default;
                    ShowMsg("理件文件夹保存成功！");
                }
                Cursor = Cursors.Default;
            }
            catch (Exception ex)
            {
                Cursor = Cursors.Default;
                ShowMsg(ex.Message);
            }
        }

        /// <summary>
        /// 检查是否有理好件的文件夹存在
        /// </summary>
        /// <returns></returns>
        private bool CheckIsOkExist()
        {
            try
            {
                bool isExist = false;
                string[] subDirectories = Directory.GetDirectories(DisposeTotalPath);
                foreach (string subDirectory in subDirectories)
                {
                    if (subDirectory.EndsWith("OK"))
                    {
                        isExist = true;
                        break;
                    }
                }
                return isExist;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        //关闭
        private void FrmDisposeMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (CheckIsOkExist())
            {
                if (DialogResult.Yes == MessageBox.Show("还存在未移动到等待开单的理好件的文件夹，关闭前要执行移动操作吗？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
                {
                    tsSave_Click(sender, e);                                            //移动已理件的文件夹   
                }
            }
        }

        //-------------------数据结构--------------
        /// <summary>
        /// 文件夹路径类
        /// </summary>
        private class FolderCL
        {
            public bool IsRoot;                 //是否是根节点
            public string FolderName;           //文件夹名称
            public string Path;                 //路径(根节点保留全路径，其他节点只保留当前路径)
            public int Level;                   //文件夹处于第几层
        }

        /// <summary>
        /// 照片结构
        /// </summary>
        private class PhotoCL
        {
            public string FileName { get; set; }        //照片名字
            public double Height { get; set; }          //高
            public double Width { get; set; }           //宽
            public int HeightPix { get; set; }          //像素高
            public int WidthPix { get; set; }           //像素宽
            public string HWcm { get; set; }            //高×宽(cm)
            public string HWin { get; set; }            //高×宽(in)
            public int DPI { get; set; }                //DPI
            public string PhotoFullName { get; set; }   //照片全路径
            public int Rank { get; set; }               //照片级别(双击时筛选不符合尺寸条件时使用)
            public RasterImageListItem Thumb { get; set; }      //缩略图
        }



    }
}
